﻿// -------------------------------------------------------------------------
//    @FileName         :    NFOnlineUtil.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-22
//    @Email            :    445267987@qq.com
//    @Module           :    NFOnlineUtil
//
// -------------------------------------------------------------------------

#include "NFOnlineUtil.h"

#include <Event/NFEventDisp.h>
#include <NFServerComm/NFServerCommon/NFIServerMessageModule.h>

#include <NFPlayerPacketSendUtil.h>
#include "NFSession.h"
#include "NFPlayer.h"
#include "NFPlayerMgr.h"
#include "NFComm/NFCore/NFServerTime.h"

int NFOnlineUtil::KickOff(uint64_t ullRoleID, int iReason, const char* reasonStr)
{
    NFPlayer* pPlayer = NFPlayer::GetObjByHashKey(ullRoleID);
    if (!pPlayer)
    {
        return 0;
    }

    LOGSVR_INFO("RoldID:" << ullRoleID << " Kickoff !Reason:" << iReason << ",Status=" << pPlayer->GetPlayerStatus() << ",TransNum=" << pPlayer->GetTransNum()); // << ". battlestatus:" << pPlayer->GetPlayerBattleExt()->DebugString());

    NFSession* pSession = pPlayer->GetClientSession();
    if (!pSession)
    {
        LOGSVR_ERROR("RoleID:" << pPlayer->GetRoleID() << " Lost Client Session");
    }

    switch (pPlayer->GetPlayerStatus())
    {
        case CACHE_STATUS_NONE:
        {
            if (pSession)
                pSession->SendConndStop();
            break;
        }
        case CACHE_STATUS_ONLINE:
        {
            if (pSession)
            {
                NFPlayerPacketSendUtil::NotifyKickOff(pPlayer, iReason, reasonStr);
                NFEventDisp::OnKickOff(pPlayer, iReason);
                if (pSession->GetDelayStopTime() < NF_ADJUST_TIMENOW_MS())
                {
                    pSession->SetDelayStopTime(NF_ADJUST_TIMENOW_MS() + 2000);
                }
            }
        }
        break;
        default:
            break;
    }

    if (pSession)
        pSession->DisConnect(SESSION_DISCONN_FROM_SERVER, iReason);

    return 0;
}

int NFOnlineUtil::KickOff(NFSession* pSession, int iReason)
{
    CHECK_NULL(0, pSession);
    if (pSession)
    {
        pSession->SendConndStop();
        pSession->DisConnect(SESSION_DISCONN_FROM_SERVER, iReason);
    }
    return 0;
}

int NFOnlineUtil::NotifyOnlineRewardData(NFPlayer* pPlayer)
{
    return 0;
}

int NFOnlineUtil::OnPlayerLevelUp(NFPlayer* pPlayer)
{
    return 0;
}
